Repository navigation
fix(tiles): one temporary name counter, and create_new lands whole or not at all - #2
Merged
Merged
Conversation
Each PosixStore::open starts its own counter at 0 and names temporary files after the process id and that counter, so two handles on one root in one process draw the same name and File::create truncates the other's file before its rename. The test writes a temporary file through each of two handles and expects two paths, each with its own bytes.
The counter behind temporary file names is now a static shared by all handles in the process instead of one per open, so two handles on one root never draw the same name. The file is created with create_new, and a name that is taken, as by an earlier process with the same id, is passed over rather than truncated. A temporary file whose write or sync fails is removed.
The module doc says a write lands whole or not at all, but PosixStore::create_new opens the path itself with create_new and writes into it. A write that fails part way, or a crash, leaves the head of the bytes at the path, and every later create_new there answers that something is already stored. The test runs itself again under a file size limit, where create_new of 64 KiB fails with EFBIG, then expects nothing at the path or under .tmp and a create_new that succeeds.
create_new now writes and syncs a temporary file, links it at the path with hard_link, which fails with AlreadyExists when something is there, removes the temporary name and syncs the directory. A failed write leaves nothing at the path, as put already did, so a retry can create it. The tree-state and publish locks and rfc9162-log's run files are made this way. The module and trait docs say so, and that the root needs hard links.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Temporary names are now unique across every
PosixStorein the process, andcreate_newwrites a temporary file and links it at the path so a cut-short write leaves nothing there.PosixStore::openstarted its own counter at 0 and named temporary files after the process id and that counter, so two handles on one root in one process drew the same name and truncated the other's file. The counter is now a static shared by all handles. The file is created withcreate_new, a name that is taken is passed over rather than truncated, and a temporary file whose write or sync fails is removed.create_newopened the path itself and wrote into it, so a write that failed part way, or a crash, left a partial file, and every latercreate_newthere answered that something was already stored. It now writes and syncs a temporary file, links it at the path, removes the temporary name and syncs the directory. The root needs hard links.create_newof 64 KiB fails with EFBIG, then expects nothing at the path or under.tmpand acreate_newthat succeeds.The branch has towncrier fragments.